const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpack = require("webpack");

module.exports = {
  mode: "production",
  entry: "/src/ts/index.ts",
  devtool: "source-map",
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: [
          "babel-loader",
          "ts-loader",
        ],
        exclude: /node_modules/,
      },
      {
        test: /\.scss$/,
        use: [
          MiniCssExtractPlugin.loader,
          {
            loader: "css-loader",
          },
          {
            loader: "resolve-url-loader",
          },
          {
            loader: "sass-loader",
            options: { sourceMap: true },
          },
        ],
      },
      {
        test: /\.art$/,
        loader: "art-template-loader",
      },
    ],
  },
  resolve: {
    preferRelative: true,
    extensions: [".tsx", ".ts", ".js", ".scss"],
  },
  output: {
    filename: "Functool.min.js",
    path: path.resolve(__dirname, "..", "dist"),
    library: {
      name: "tool",
      type: "umd",
      export: "default",
    },
    clean: true,
    publicPath: "/",
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: "Functool.min.css",
    }),
    new webpack.DefinePlugin({
      FUNCTOOL_VERSION: `"${require("../package.json").version}"`,
      "process.env": {
        NODE_ENV: JSON.stringify(process.env.NODE_ENV),
      },
    }),
  ],
};
